package mdbs;

import javax.annotation.Resource;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenContext;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

@MessageDriven(mappedName = "jms/tQueue")
public class TMDB implements MessageListener {
    
    
    @Resource
    private MessageDrivenContext mdc;
    
    public void onMessage(Message message) {        
        TextMessage msg = null;
        try {
            if (message instanceof TextMessage) {
                msg = (TextMessage) message;
                System.out.println("A Message received in TMDB: " + msg.getText());
            } else {
                System.out.println("Message of wrong type: " + message.getClass().getName());                
            }
        } catch (JMSException e) {
            e.printStackTrace();
            mdc.setRollbackOnly();
        } catch (Throwable te) {
            te.printStackTrace();
        }                
    }
    
    
}
